#include "widget.h"
#include "ui_widget.h"

#include <QPushButton>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget),
    button(nullptr)
{
    ui->setupUi(this);
    QPushButton* switchButton = new QPushButton(this);
    switchButton->setText("switch");
    switchButton->move(300, 300);
    connect(switchButton, &QPushButton::clicked, this, &Widget::switchHandler);

    button = new QPushButton(this);
    button->setText("button");
    button->move(200, 300);
    connect(button, &QPushButton::clicked, this, &Widget::buttonHandler);
}

Widget::~Widget()
{
    delete ui;
}

void Widget::switchHandler()
{
    if (button->isEnabled()) {
        button->setEnabled(false);
    }
    else {
        button->setEnabled(true);
    }
}

void Widget::buttonHandler()
{
    qDebug() << "button clicked";
}
